package cn.daniellee.plugin.pm.menu;

import cn.daniellee.plugin.pm.PartnerMission;
import cn.daniellee.plugin.pm.component.ItemGenerator;
import cn.daniellee.plugin.pm.core.MissionCore;
import cn.daniellee.plugin.pm.model.Invite;
import cn.daniellee.plugin.pm.model.PlayerData;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

import java.util.List;

public class InviteMenu {

	public static Inventory generate(Player player) {
		List<Invite> invites = MissionCore.getPlayerInvitation(player.getName());
		Inventory menu = Bukkit.createInventory(new InviteMenuHolder(), 27, PartnerMission.getInstance().getConfig().getString("menu.invite.title", "&6&lPending Invitations").replace("&", "§"));

		String playerName = PartnerMission.getInstance().getConfig().getString("menu.invite.button.player.name", "&a&lPlayer: &b&l{player}");
		List<String> playerLore = PartnerMission.getInstance().getConfig().getStringList("menu.invite.button.player.lore");
		for (int i = 0; i < 27; i++) {
			if (i >= invites.size()) break;
			PlayerData playerData = PartnerMission.getInstance().getStorage().getPlayerByName(invites.get(i).getInviter());
			menu.setItem(i, ItemGenerator.getSkullItem(playerData.getName(), playerData.getTexture(), playerName.replace("{player}", playerData.getName()), MissionCore.formatPlayerLore(playerLore, playerData)));
		}
		return menu;
	}

	public static class InviteMenuHolder implements InventoryHolder {
		@Override
		public Inventory getInventory() {
			return Bukkit.createInventory(null, 27);
		}
	}
}
